package com.sleep.psy.external_server.business.adjustment.controller;


import com.alibaba.fastjson.JSON;
import com.sleep.psy.external_server.business.adjustment.entity.vo.AddPlanRecordReq;
import com.sleep.psy.external_server.business.adjustment.service.AdjustmentPlanRecordService;
import com.sleep.psy.external_server.result.Result;
import com.sleep.psy.external_server.result.ResultEnum;
import com.sleep.psy.external_server.result.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 调节记录表 前端控制器
 * </p>
 *
 * @author wenliguo
 * @since 2025-08-12
 */
@Api(tags = "调节记录")
@RestController
@RequestMapping("/adjustmentPlanRecord")
public class AdjustmentPlanRecordController {

    protected Logger logger = LoggerFactory.getLogger(AdjustmentPlanRecordController.class);

    @Autowired
    private AdjustmentPlanRecordService planRecordService;

    /**
     * 提交调节记录
     * @author wenliguo
     * @date 2025/6/17 16:36
     * @param req 提交参数
     * @return com.sleep.psy.main_server.result.Result
     */
    @PostMapping("/addPlanRecord")
    @ApiOperation(value = "提交调节记录")
    public Result addPlanRecord(@Valid @RequestBody AddPlanRecordReq req) {

        logger.info("提交调节记录参数:{}", JSON.toJSONString(req));
        try {
            return planRecordService.addPlanRecord(req);
        } catch (Exception e) {
            logger.error("提交调节记录出错", e);
            return ResultUtil.error(ResultEnum.SERVER_INTERNAL_ERROR);
        }
    }
}

